﻿<%@ WebHandler Language="C#" Class="auto" %>

using System;
using System.Web;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Json; 
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
public class auto : IHttpHandler {
    public void ProcessRequest (HttpContext context) {
        string str11=context.Request["sort"].ToString();
        context.Response.ContentType = "application/json";
        Dictionary<string, string> data = new Dictionary<string, string>();
        Database db = DatabaseFactory.CreateDatabase();
        var cmd = db.GetStoredProcCommand("proc_DeviceInfo_t_autocomplete");
        var reader = db.ExecuteReader(cmd);
        int i = 0;
        while (reader.Read())
        {
            i++;
            string str = reader.GetString(0);
            data.Add(str, i.ToString());
        }
        DataContractJsonSerializer serializer = new DataContractJsonSerializer(data.GetType());
        
        using (MemoryStream ms = new MemoryStream())
        {
            serializer.WriteObject(ms, data);
            context.Response.Write(System.Text.Encoding.UTF8.GetString(ms.ToArray()));
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}